import numpy as np
from scipy import stats
import pandas as pd

dfx = pd.read_csv(r'testx.csv')
dfy = pd.read_csv(r'testy.csv')
# X
x = np.mat(dfx.mean(), dtype=float).T

# Y
y = np.mat(dfy.mean(), dtype=float).T

n = dfx.shape[0]
m = dfy.shape[0]
tempA1 = np.mat(0)
tempA2 = np.mat(0)
# n = 10
i = 0
while i < n:
    array_x = np.mat(np.array(dfx.iloc[i])).T-x
    a1 = np.matmul(array_x, array_x.T)
    tempA1 = a1 + tempA1
    i = i+1
j = 0
while j < m:
    array_y = np.mat(np.array(dfy.iloc[j])).T - y
    a2 = np.matmul(array_y, array_y.T)
    tempA2 = a2 + tempA2
    j = j + 1

D2 = (n + m - 2) * ((x-y).T) * np.linalg.inv(tempA1 + tempA2) * (x - y)

T2 = (n*m / (n + m)) * D2

F = ((n + m - 4 - 1) / ((n + m - 2) * 4)) * T2
# T = stats.t.isf(0.01, F)
# T = stats.f.ppf(1-0.01, 4, 28)
T = stats.f.ppf(0.99, 4, 11)
if F > T:
    print("在α=0.01的置信水平下拒绝原假设")
else:
    print("在α=0.01的置信水平下接收原假设")